package com.yanqu.road.server.logic.activity.condition.rank;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.args.WasheScoreRankArgs;
import com.yanqu.road.entity.activity.washe.config.WasheConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseRankActivityCondition;
import com.yanqu.road.server.manger.activity.washe.WasheMgr;
import com.yanqu.road.server.manger.cross3.ChannelRankActivityMgr;

import java.math.BigInteger;

public class WasheScoreSmallRankCondition extends BaseRankActivityCondition {

    public WasheScoreSmallRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.WasheScoreSmallRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.WasheScoreSmallRank.getValue(), handle);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        WasheScoreRankArgs args = (WasheScoreRankArgs) object;
        setValue(BigInteger.valueOf(args.getScore()));

        WasheConfig washeConfig = WasheMgr.getWasheConfig();
        if (washeConfig == null || args.getScore() <= washeConfig.getRankNeedScore()) {
            return; // 具体为啥看这个getRankNeedScore()的调用
        }

        if (activityInfo.getType() == eActivityType.ChannelRankActivity.getValue()) {
            ChannelRankActivityMgr.userRankChange(activityInfo.getActivityId(), activityConditionInfo.getType(), getValue().longValue(), player.getUserId(), "");
        }
    }
}
